package com.zkthink.ceres.common.utils;

import com.zkthink.exception.BizException;
import io.rong.RongCloud;
import io.rong.messages.VoiceMessage;
import io.rong.methods.message._private.Private;
import io.rong.methods.message.expansion.Expansion;
import io.rong.models.message.ExpansionModel;
import io.rong.models.message.PrivateMessage;
import io.rong.models.response.ResponseResult;

import java.util.HashMap;

/**
 * @Author Xiaoyan
 * @create 2022/1/29 15:01
 * app-key: 8luwapkv8w64l
 * app-secret: WjwtNl7fbdD
 */
public class mian {
    public static void main(String[] args) {
        RongCloud rongCloud = RongCloud.getInstance("8luwapkv8w64l", "WjwtNl7fbdD");
        VoiceMessage voiceMessage = new VoiceMessage("hello", "helloExtra", 20L);
        Private Private = rongCloud.message.msgPrivate;
        PrivateMessage privateMessage = new PrivateMessage()
                .setSenderId("1356409133430996992")
                .setTargetId(new String[]{"1475797944132173824"})
                .setObjectName(voiceMessage.getType())
                .setContent(voiceMessage)
                .setPushContent("")
                .setPushData("{\"pushData\":\"hello\"}")
                .setPushExt("{\"title\":\"\",\"forceShowPushContent\":0,\"pushConfigs\":{\"HW\":{\"channelId\":\"\"},\"MI\":{\"channelId\":\"\"},\"OPPO\":{\"channelId\":\"\"}}}")
                .setCount("4")
                .setVerifyBlacklist(0)
                .setIsPersisted(0)
                .setIsCounted(0)
                .setIsIncludeSender(0);
        try {
            ResponseResult privateResult = Private.send(privateMessage);
            System.out.println("send private getReqBody:  " + privateResult.getReqBody());
            System.out.println("send private message:  " + privateResult.toString());
        } catch (Exception e) {
            throw new BizException(e.getMessage());
        }

        Expansion expansion = rongCloud.expansion;
        ExpansionModel msg = new ExpansionModel();
        msg.setUserId("1356409133430996992");
        msg.setTargetId("1475797944132173824");
        msg.setConversationType(1);
        HashMap<String, String> kv = new HashMap<String, String>();
        kv.put("type1", "1");
        kv.put("type2", "2");
        kv.put("type3", "3");
        kv.put("type4", "4");
        msg.setExtraKeyVal(kv);
        ResponseResult result = null;
        try {
            result = expansion.set(msg);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("set expansion:  " + result.toString());
    }
}
